//package com.fj.web;
//
//import io.github.resilience4j.bulkhead.annotation.Bulkhead;
//import io.github.resilience4j.circuitbreaker.annotation.CircuitBreaker;
//import io.github.resilience4j.ratelimiter.annotation.RateLimiter;
//import io.github.resilience4j.retry.annotation.Retry;
//import org.springframework.http.HttpStatus;
//import org.springframework.http.ResponseEntity;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.util.Random;
//
///**
// * @author fj
// * @date 2023/12/26 16:01
// */
//@RestController
//public class UserController {
//
//    @RateLimiter(name="backendA",fallbackMethod = "fallback")
//    @RequestMapping(value = "test1")
//    public ResponseEntity test1(){
//        System.out.println("---test1---");
//        return ResponseEntity.ok().body("success");
//    }
//
//    @RequestMapping(value = "test2")
//    @CircuitBreaker(name = "backendB", fallbackMethod = "fallback")
//    public ResponseEntity test2(){
//        Random random = new Random();
//        if (random.nextInt(100) > 20){
//            System.out.println("随机异常");
//            throw new RuntimeException("随机异常");
//        }
//        System.out.println("---test2---");
//        return ResponseEntity.ok().body("success");
//    }
//
//    @RequestMapping(value = "test3")
//    @Bulkhead(name = "backendA", fallbackMethod = "fallback")
//    public ResponseEntity test3(){
//        System.out.println("---test3---"+Thread.currentThread().getName());
//        Random random = new Random();
//        if (random.nextInt(100) > 20){
//            System.out.println("随机异常"+Thread.currentThread().getName());
//            throw new RuntimeException("随机异常");
//        }
//        return ResponseEntity.ok().body("success");
//    }
//
//    @RequestMapping(value = "test4")
//    @Retry(name = "backendA", fallbackMethod = "fallback")
//    public ResponseEntity test4(){
//        System.out.println("---test4---"+Thread.currentThread().getName());
//        Random random = new Random();
//        if (random.nextInt(100) > 20){
//            System.out.println("随机异常"+Thread.currentThread().getName());
//            throw new RuntimeException("随机异常");
//        }
//        return ResponseEntity.ok().body("success");
//    }
//
//    public ResponseEntity fallback(Throwable throwable){
//        System.out.println("---fallback---");
//        return new ResponseEntity("请求频繁",HttpStatus.BAD_REQUEST);
//    }
//
//}
